#include "gtest/gtest.h"
#include "TDBase.h"

TEST (PathFinder, Find)
{
	StageMap map;

	//	+--+--+--+--+
	//	| 0| 1| 2| 3|
	//	+--+--+--+--+  +--+
	//	| 4|  | 5| 6|  | 7|
	//	+--+  +--+--+  +--+
	
	map.Clear();
	map.Append(MapBrick(0,vector3di( 0,0,4),0,false,true,-1, 1, 4,-1));
	map.Append(MapBrick(0,vector3di( 2,0,4),0,false,true,-1, 2,-1, 0));
	map.Append(MapBrick(0,vector3di( 4,0,4),0,false,true,-1, 3, 5, 1));
	map.Append(MapBrick(0,vector3di( 6,0,4),0,false,true,-1,-1, 6, 2));
	map.Append(MapBrick(0,vector3di( 0,0,2),0,false,true, 0,-1,-1,-1));
	map.Append(MapBrick(0,vector3di( 4,0,2),0,false,true, 2, 6,-1,-1));
	map.Append(MapBrick(0,vector3di( 6,0,2),0,false,true,-1,-1, 5, 3));
	map.Append(MapBrick(0,vector3di(10,0,2),0,false,true,-1,-1,-1,-1));

	PathFinder finder;
	MapPath path;

	for (int i=0; i<100; i++)
	{
		for (int j=0; j<7; j++)
		{
			path.Clear();
			ASSERT_FALSE (finder.Find(map, j, 7, path));
			ASSERT_FALSE (finder.Find(map, 7, j, path));
		}

		path.Clear();
		ASSERT_TRUE (finder.Find(map, 4, 5, path));

		int correctPath[] =  {4, 0, 1, 2, 5};
		int correctSize = sizeof(correctPath) / sizeof(int);
		ASSERT_EQ (correctSize, path.Size());
		ASSERT_EQ (5, path.EndBrickIdx());

		vector3di correctVert[] = {
			vector3di(0,0,3),
			vector3di(1,0,4),
			vector3di(3,0,4),
			vector3di(4,0,3),
			vector3di(4,0,2)
		};

		for (int i=0; i<correctSize; i++)
		{
			ASSERT_EQ (correctPath[i], path[i]);
			ASSERT_EQ (correctVert[i], path.VertAt(i));
		}
	}
}

